package com.gtw.pattern;

import com.gtw.pattern.abstrac.*;
import com.gtw.pattern.simple.ConcreteProduct2;
import com.gtw.pattern.simple.commonfactory.ConcreteCreator;
import com.gtw.pattern.simple.ConcreteProduct1;
import com.gtw.pattern.simple.commonfactory.Creator;
import com.gtw.pattern.simple.Product;
import com.gtw.pattern.simple.lazyfactory.ProductCreator;
import com.gtw.pattern.simple.manyfactory.Product1Factory;
import com.gtw.pattern.simple.onefactory.StaticCreator;

public class Client {

    public static void main(String[] args){
        /**
         * 通用工厂
         */
        Creator creator = new ConcreteCreator();
        Product product1 = creator.createProduct(ConcreteProduct1.class);
        product1.method1();
        product1.method2();

        System.out.println("--------------分割线------------");

        /**
         * 只需要一个工厂类
         */
        Product product2 = StaticCreator.createProduct(ConcreteProduct2.class);
        product2.method1();
        product2.method2();

        System.out.println("--------------分割线------------");

        /**
         * 多工厂类
         */

        Product product3 = (new Product1Factory()).createProduct();
        product3.method1();
        product3.method2();

        System.out.println("--------------分割线------------");

        /**
         * 延迟工厂
         */
        Product product4 = ProductCreator.createProduct("product2");
        product4.method1();
        product4.method2();

        System.out.println("--------------分割线------------");

        /**
         * 抽象工厂
         * 具体产品等级是由不同实现工厂来定的,如1等级的只能由creator1来生成
         */
        AbstractCreator creator1 = new Creator1();
        AbstractCreator creator2 = new Creator2();
        //生成A1对象
        ProductA productA1 = creator1.createProductA();
        productA1.doSomething();
        //生成B2对象
        ProductB productB2 = creator2.createProductB();
        productB2.doSomething();
    }
}
